<?php

/* обработчик для кнопок на форме комментария */

require_once('./configure.php');
global $cfg;

if (isset($_POST['edit_button'])) {
    //edit action
    
    $client_db = new $cfg->dbmethod;
    $commentary = $client_db->getCommentaryByID($_REQUEST['msgid'], $_REQUEST['cmtid']);
    
    $inputname = '<input name="author" type="text" id="name" value="' . "${commentary['author']}" . '"/>';
    $inputtext = '<textarea name="message" id="message">' . "${commentary['text']}" . '</textarea>' ;
    $submittype = '<input type="submit" name="upd_cmt_btn" value="Update" />';
    
    $hiddenmsgsinput = '<input type="hidden" value="' . $_REQUEST['msgid'] . '" name="msgid"/>' . "\n";
    $hiddencommentinput = '<input type="hidden" value="' . $_REQUEST['cmtid'] . '" name="cmtid"/>';
    $hiddeninput = $hiddenmsgsinput . $hiddencommentinput;
    
    include ($cfg->dirroot . '/views/edit_text.html');

    
} else if (isset($_POST['delete_button'])) {
    //delete action
    $client_db = new $cfg->dbmethod;
    $success = $client_db->deleteCommentary($_REQUEST['msgid'], $_REQUEST['cmtid']);

    if ($success) $statusmsg = "Commentary #${_REQUEST['cmtid']} from Message #${_REQUEST['msgid']} successfully deleted"; 
    else $statusmsg = "Error: Commentary #${_REQUEST['cmtid']} from Message #${_REQUEST['msgid']} wasn't deleted"; 
    $htmlgen = new HTMLGenerate();
    include ($cfg->dirroot . '/views/main.html');
}